package dataMapper;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import dataEntity.VunerablePopsAndEnvHealth;

public class VunerablePopsAndEnvHealthMapper {
	public static  Map<String,Map<String,VunerablePopsAndEnvHealth>> process(BufferedReader br){
		Map<String,Map<String,VunerablePopsAndEnvHealth>> map = new HashMap<String,Map<String,VunerablePopsAndEnvHealth>> ();
		try {
			br.readLine();
			while(br.ready()){
				VunerablePopsAndEnvHealth object = buildObject(br.readLine());

				Map<String,VunerablePopsAndEnvHealth> stateMap = map.get(object.getCHSI_State_Abbr());
				if(stateMap == null) stateMap = new HashMap<String,VunerablePopsAndEnvHealth>();
				stateMap.put(object.getCHSI_County_Name(), object);
				map.put(object.getCHSI_State_Abbr(), stateMap);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return map;
	}
	
	public static void info(Map<String,Map<String,VunerablePopsAndEnvHealth>> map){
		TreeSet<Integer> infoSet1 = new TreeSet<Integer>();
		TreeSet<Integer> infoSet2 = new TreeSet<Integer>();
		TreeSet<Integer> infoSet3 = new TreeSet<Integer>();
		TreeSet<Integer> infoSet4 = new TreeSet<Integer>();
		TreeSet<Integer> infoSet5 = new TreeSet<Integer>();
		TreeSet<Integer> infoSet6 = new TreeSet<Integer>();
		TreeSet<Integer> infoSet7 = new TreeSet<Integer>();
		Set<String> stateSet = map.keySet();
		for(String s : stateSet){
			Map<String, VunerablePopsAndEnvHealth> countyMap = map.get(s);
			Set<String> countySet = countyMap.keySet();
			for(String countyString : countySet){
				VunerablePopsAndEnvHealth dem = countyMap.get(countyString);
				infoSet1.add(dem.getCarbon_Monoxide_Ind());
				infoSet2.add(dem.getLead_Ind());
				infoSet3.add(dem.getNitrogen_Dioxide_Ind());
				infoSet4.add(dem.getOzone_Ind());
				infoSet5.add(dem.getParticulate_Matter_Ind());
				infoSet6.add(dem.getSulfur_Dioxide_Ind());
				infoSet7.add(dem.getToxic_Chem());
			}
		}
		System.out.println("getCarbon_Monoxide_Ind Smallest " + infoSet1.first() + " Largest " + infoSet1.last());
		System.out.println("getLead_Ind Smallest " + infoSet2.first() + " Largest " + infoSet2.last());
		System.out.println("getNitrogen_Dioxide_Ind Smallest " + infoSet3.first() + " Largest " + infoSet3.last());
		System.out.println("getOzone_Ind Smallest " + infoSet4.first() + " Largest " + infoSet4.last());
		System.out.println("getParticulate_Matter_Ind Smallest " + infoSet5.first() + " Largest " + infoSet5.last());
		System.out.println("getSulfur_Dioxide_Ind Smallest " + infoSet6.first() + " Largest " + infoSet6.last());
		System.out.println("getToxic_Chem Smallest " + infoSet7.first() + " Largest " + infoSet7.last());
	}
	
	public static  VunerablePopsAndEnvHealth buildObject(String inLine){
		String[] line = inLine.split(",");
		VunerablePopsAndEnvHealth object = new VunerablePopsAndEnvHealth();
		
		object.setState_FIPS_Code(line[0]);
		object.setCounty_FIPS_Code(line[1]);
		object.setCHSI_County_Name(line[2]);
		object.setCHSI_State_Name(line[3]);
		object.setCHSI_State_Abbr(line[4]);
		object.setStrata_ID_Number(line[5]);
		object.setNo_HS_Diploma(line[6]);
		object.setUnemployed(line[7]);
		object.setSev_Work_Disabled(line[8]);
		object.setMajor_Depression(line[9]);
		object.setRecent_Drug_Use(line[10]);
		object.setEcol_Rpt(line[11]);
		object.setEcol_Rpt_Ind(line[12]);
		object.setEcol_Exp(line[13]);
		object.setSalm_Rpt(line[14]);
		object.setSalm_Rpt_Ind(line[15]);
		object.setSalm_Exp(line[16]);
		object.setShig_Rpt(line[17]);
		object.setShig_Rpt_Ind(line[18]);
		object.setShig_Exp(line[19]);
		object.setToxic_Chem(line[20]);
		object.setCarbon_Monoxide_Ind(line[21]);
		object.setNitrogen_Dioxide_Ind(line[22]);
		object.setSulfur_Dioxide_Ind(line[23]);
		object.setOzone_Ind(line[24]);
		object.setParticulate_Matter_Ind(line[25]);
		object.setLead_Ind(line[26]);
		object.setEH_Time_Span(line[27]);
		return object;
	}

}
